<template>
  <div>
    <div style="display: flex; flex-direction: row-reverse;">
      <div class="button-style" style="margin-left: 20px; background: #FFEEEF; border: 1px solid #FA533C;" @click="handleClearReserve">
        <span style="color: #FA533C;">清除非正选人员名单</span>
      </div>
      <div class="button-style" style="margin-left: 20px; background: #F1FFFA; border: 1px solid #04C670;" @click="handleToReserve">
        <span style="color: #04C670;">全部转预选</span>
      </div>
      <div class="button-style" style="background: #FEF2E8; border: 1px solid #F46D02;" @click="handleToFormal">
        <span style="color: #F46D02;">全部转正选</span>
      </div>
    </div>
    <el-table
      :data="tableData"
      border
      class="xpaas-table-class"
      row-class-name="xpaas-row-class"
      cell-class-name="xpaas-cell-class"
      header-row-class-name="xpaas-header-row-class"
      header-cell-class-name="xpaas-header-cell-class"
      style="margin-top: 15px;">
      <el-table-column prop="classname" label="教学班" align="center" />
      <el-table-column prop="coursenumber" label="课程编号" align="center" />
      <el-table-column prop="coursename" label="课程名称" align="center" />
      <el-table-column prop="reservenum" label="额定人数" align="center" />
      <el-table-column prop="preselectionnum" label="预选人数" align="center" />
      <el-table-column prop="positivenum" label="正选人数" align="center" />
      <el-table-column prop="bx" label="系" align="center" />
      <el-table-column prop="jyroom" label="课程承担教研室" align="center" />
      <el-table-column prop="createtime" label="创建时间" sortable align="center" />
    </el-table>
  </div>
</template>

<script>
import { queryClassList, batchUpdateByClassNo, batchDeleteByClassNo } from '@/api/trainingManagement/place'
export default {
  data() {
    return {
      selectRows: this.$route.query.queryList,
      tableData: [],
      classNos: []
    }
  },
  mounted() {
    if (this.selectRows === undefined) {
      this.$message.warning('教学班信息已丢失！')
    } else {
      this.classNos = []
      this.selectRows.forEach(item => {
        this.classNos.push(item.classno)
      })
      this.handleSearch()
    }
  },
  methods: {
    handleToFormal: function () {
      if (this.classNos.length === 0) {
        this.$message.warning('教学班信息已丢失！')
      } else {
        const params = {
          classno: this.classNos.join(','),
          studentstate: '正选'
        }
        batchUpdateByClassNo(params).then(res => {
          if (res.data.code === 200) {
            this.handleSearch()
            this.$message.success('全部转正选成功！')
          } else {
            this.$message.warning('全部转正选失败！')
          }
        })
      }
    },
    handleToReserve: function () {
      if (this.classNos.length === 0) {
        this.$message.warning('教学班信息已丢失！')
      } else {
        const params = {
          classno: this.classNos.join(','),
          studentstate: '预选'
        }
        batchUpdateByClassNo(params).then(res => {
          if (res.data.code === 200) {
            this.handleSearch()
            this.$message.success('全部转预选成功！')
          } else {
            this.$message.warning('全部转预选失败！')
          }
        })
      }
    },
    handleClearReserve: function () {
      this.$confirm('确认清除非正选人员名单？', '操作提示', {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        const params = {
          classno: this.classNos.join(',')
        }
        batchDeleteByClassNo(params).then(res => {
          if (res.data.code === 200) {
            this.handleSearch()
            this.$message.success('清除非正选人员名单成功！')
          } else {
            this.$message.warning('清除非正选人员名单失败！')
          }
        })
      })
    },
    handleSearch: function () {
      const params = {
        classno: this.classNos.join(',')
      }
      queryClassList(params).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .button-style {
    float: left;
    background: #f1f8fe;
    border: 1px solid #51aef6;
    width: auto;
    height: 28px;
    line-height: 28px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    box-sizing: border-box;
    > span {
      font-size: 14px;
      color: #51aef6;
    }
  }
  @fontFamily:"Microsoft YaHei";
  .xpaas-table-class {
    border: 1px solid #004ca7;
    border-radius: 9px;
    ::v-deep div.el-table__header-wrapper {
      table.el-table__header {
        thead {
          tr.xpaas-header-row-class {
            padding: 0;
            height: 60px;
            background-color: #edf2f9;
            font-size: 16px;
            font-family: @fontFamily;
            font-weight: bold;
            line-height: 20px;
            color: #004ca7;
            th.xpaas-header-cell-class {
              font-weight: bold;
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              background-color: #edf2f9;
              div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
          }
        }
      }
    }
    ::v-deep div.el-table__body-wrapper {
      table.el-table__body {
        tbody {
          tr.xpaas-row-class {
            td.xpaas-header-cell-class {
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              background-color: #edf2f9;
              div.cell {
                font-size: 16px;
                font-weight: bold;
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
            td.xpaas-cell-class {
              height: 60px;
              border-right: 1px solid #c7d7eb;
              border-left: 0;
              border-bottom: 1px solid #c7d7eb;
              div.cell {
                font-family: @fontFamily;
                color: #004ca7;
              }
            }
          }
        }
      }
    }
  }
</style>
